package com.tonghe.controller;

import com.tonghe.annotation.SystemLog;
import com.tonghe.domain.ResponseResult;
import com.tonghe.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Date:2022/2/14- 02- 14- 19:39
 * @author: tonghe
 **/

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
    * @description:热门文章查询
    * @param： []
    * @return： com.tonghe.domain.ResponseResult
    */
    @GetMapping("/hotArticleList")
    public ResponseResult hotArticleList(){
        ResponseResult result = articleService.hotArticleList();
        return result;
    }

    /**
    * @description: 文章列表
    * @param： [pageNum, pageSize, categoryId]
    * @return： com.tonghe.domain.ResponseResult
    */
    @GetMapping("/articleList")
    public ResponseResult articleList(Integer pageNum, Integer pageSize,Long categoryId){
        return articleService.articleList(pageNum,pageSize,categoryId);
    }

    /**
    * @description: 获取文章详情
    * @param： [id]
    * @return： com.tonghe.domain.ResponseResult
    */
    @SystemLog(businessName = "文章详情")
    @GetMapping("/{id}")
    public ResponseResult getArticleDetail(@PathVariable("id")long id){
        return articleService.getArticleDetail(id);
    }

    /**
     * @description: 更改文章浏览量
     * @param： [id]
     * @return： com.tonghe.domain.ResponseResult
     */
    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable("id") Long id) {
        return articleService.updateViewCount(id);
    }
}
